const Koa = require('koa');
const fs = require('fs')
  // const log = require('./mode/index')
const app = new Koa();
const Router = require('koa-router')

let koarouter = new Router()

koarouter.get('/', async(ctx) => {
  let html = `<a href="/koarouterchild/cs">cs</a>`
  ctx.body = html
})


let koarouterchild = new Router()

koarouterchild.get('/cs', async(ctx) => {
  let htmls = `我是测试`
  ctx.body = htmls
})


let router = new Router()
router.use('/', koarouter.routes(), koarouter.allowedMethods())
router.use('/koarouterchild', koarouterchild.routes(), koarouterchild.allowedMethods())
app.use(router.routes()).use(router.allowedMethods())

// app.use(async ctx => {
// app.context.db = db();
// console.log(ctx.db);ctx.require.url;
// let ur = ctx.require.url;
// let ur = ctx.request.url
// let html = await root(ur)
// ctx.body = `Hello World ${ur}`;
// ctx.body = html
//  const ms = Date.now() - start;
// console.log(`${ctx} ${ctx.url} - ${ms}`);
// });

app.listen(3000);
